
/*
 * MonthlyTopQuantitySales.java this class is for displaying the screen for the
 * monthly top sales in terms of quantity.
 *
 * Created on 22-Apr-2011, 18:53:45
 */

package pos.ui.screen.administrator;

import pos.control.ReportsViewControl;
import pos.interfaces.Messages;
import pos.reports.SalesBarChart;
import pos.reports.SalesPieChart;
import pos.storage.db.mysql.SelectQueryTableModel;
import pos.storage.db.sql.SQL;

/**
 *
 * @author Parvez
 */
public class MonthlyTopQuantitySales extends javax.swing.JPanel {

    private String nodeTitle = Messages.REPORTS_SALES_MONTHLY_CHART_TOP_10_QUANTITY_TITLE;
    private SelectQueryTableModel sTableModel = new SelectQueryTableModel();
    
    private String chartTitle = Messages.REPORTS_SALES_MONTHLY_CHART_TOP_10_QUANTITY_TITLE;
    private String chartQuery = SQL.REPORT_TOP10_BY_QUANTITY;
    private String chartRows = SQL.numREPORT_TOP10_BY_QUANTITY;
    private String chartParam1 = "itemItemName";
    private String chartParam2 = "numPurchases";
    
    /**
     * Creates new form DailySales
     */
    public MonthlyTopQuantitySales() {
        initComponents();
        ReportsViewControl adminControl = new ReportsViewControl();
        adminControl.genTable(sTableModel, this.chartQuery); //null will perform select *
    }

    /**
     * String of the node title
     * 
     * @return String Name of the node in the tree
     */
    @Override
    public String toString(){
        return nodeTitle;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jTable1.setModel(sTableModel);
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("PieChart");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("BarChart");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(110, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addGap(136, 136, 136))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
            .addGap(0, 400, Short.MAX_VALUE)
            .addGap(0, 400, Short.MAX_VALUE)
            .addGap(0, 400, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Pressing the button will display a sales pie chart
     * 
     * @param evt ActionEvent for clicking the button
     */
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        SalesPieChart report = new SalesPieChart(chartTitle, chartQuery, chartRows, chartParam1, chartParam2);
        report.create();
}//GEN-LAST:event_jButton1ActionPerformed

    /**
     * Pressing the button will display the sales bar chart
     * 
     * @param evt ActionEvent for clicking the button
     */
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        SalesBarChart report = new SalesBarChart(chartTitle, chartQuery, chartRows, chartParam1, chartParam2);
        report.create();
}//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
